package view;

import client.Client;
import javax.swing.JLabel;
import javax.swing.JTextField;
import java.awt.Color;
import java.awt.Font;
import javax.swing.border.BevelBorder;
import javax.swing.border.CompoundBorder;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class ConnectView extends ChessOnlineView {
	private JTextField tfIP;
	private JTextField tfPort;

	public ConnectView(Client mainScreen) {
		super(mainScreen);
		setLayout(null);
		
		JLabel lblNewLabel_1 = new JLabel("IP :");
		lblNewLabel_1.setFont(new Font("Tahoma", Font.PLAIN, 15));
		lblNewLabel_1.setForeground(Color.BLUE);
		lblNewLabel_1.setBounds(26, 38, 46, 14);
		add(lblNewLabel_1);
		
		JLabel lblNewLabel = new JLabel("PORT :");
		lblNewLabel.setForeground(Color.BLUE);
		lblNewLabel.setFont(new Font("Tahoma", Font.PLAIN, 15));
		lblNewLabel.setBounds(26, 77, 61, 14);
		add(lblNewLabel);
		
		tfIP = new JTextField();
		tfIP.setForeground(Color.GREEN);
		tfIP.setOpaque(false);
		tfIP.setBounds(97, 35, 109, 20);
		add(tfIP);
		tfIP.setColumns(10);
		
		tfPort = new JTextField();
		tfPort.setForeground(Color.GREEN);
		tfPort.setOpaque(false);
		tfPort.setBounds(97, 74, 109, 20);
		add(tfPort);
		tfPort.setColumns(10);
		
		JButton btnConnect = new JButton("Connect");
		btnConnect.setOpaque(false);
		btnConnect.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				System.out.println("dasdsa");
				String ip =  tfIP.getText();
				String port = tfPort.getText();
				if(!ip.equals("")){
					mMainScreen.setIpServer( ip);
				}
				if(!port.equals("")){
					mMainScreen.setPort(Integer.parseInt(port));
				}
				new Thread(mMainScreen).start();
			}
		});
		btnConnect.setBounds(66, 117, 89, 23);
		add(btnConnect);
		
	}
}
